package cmd

import (
	"fmt"
	"github.com/spf13/cobra"
	"github.com/zeromicro/go-zero/core/logx"
)

var rootCmd = &cobra.Command{

	Use:   "tbox",
	Short: "treasure box",
	Long:  "treasure box platform",
	//命令遇到错误时不显示使用方法
	SilenceUsage: false,
	Args: func(cmd *cobra.Command, args []string) error {
		//if len(args) < 1 {
		//	return errors.New("至少需要一个参数")
		//}
		return nil
	},
	PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
		return nil
	},
	PreRun: func(cmd *cobra.Command, args []string) {
	},
	Run: func(cmd *cobra.Command, args []string) {
		tip()
	},
}

func tip() {
	fmt.Println("欢迎使用tbox平台系统, -h 参数查看帮助文档")
}

func initCmd() {
	rootCmd.AddCommand(newVersionCommand())
	rootCmd.AddCommand(newRunCommand())
}

func Execute() {
	initCmd()
	if err := rootCmd.Execute(); err != nil {
		logx.Errorf("Execute error:%v\n", err)
	}
}
